package com.kaikeba.web;

import com.kaikeba.service.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author: Gyx
 * @Date: 2021/2/19 18:28
 */
@WebServlet(urlPatterns = {"/delete"},initParams = {
        @WebInitParam(name = "code",value = "utf-8")
})
public class DeleteServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String stuId = req.getParameter("stuId");
        StudentService service = new StudentService();
        boolean b = service.get().deleteStu(Integer.parseInt(stuId));
        PrintWriter writer = resp.getWriter();
        if(b){
            writer.println("<script>alert('删除成功');location.href='index.jsp'</script>");
        }else {
            writer.println("<script>alert('删除失败');location.href='index.jsp'</script>");
        }
    }

    @Override
    public void destroy() {
        System.out.println("DeleteServlet销毁");
    }

    @Override
    public void init() throws ServletException {
        System.out.println("DeleteServlet初始化");
    }
}
